package net.orange.architecture.audit;

import java.util.Formatter;
import java.util.Locale;

/**
 * The database operation event sql & run information.
 */
public class DatabaseAuditInfo implements IAuditInfo {

	/**
	 * The database operation sql statement.
	 */
	private String sql;

	/**
	 * The sql statement runtime consume.
	 */
	private long consume;

	/**
	 * The constructor with the sql statement and time consume.
	 * 
	 * @param sql
	 *            The database operation
	 * @param consume
	 *            The time consume.
	 */
	public DatabaseAuditInfo(String sql, long consume) {
		this.sql = sql;
		this.consume = consume;
	}

	/**
	 * @return Returns the consume.
	 */
	public long getConsume() {
		return consume;
	}

	/**
	 * @param consume
	 *            The consume to set.
	 */
	public void setConsume(long consume) {
		this.consume = consume;
	}

	/**
	 * @return Returns the sql.
	 */
	public String getSql() {
		return sql;
	}

	/**
	 * @param sql
	 *            The sql to set.
	 */
	public void setSql(String sql) {
		this.sql = sql;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.audit.IAuditInfo#toInfo()
	 */
	public String toInfo() {
		StringBuilder sb = new StringBuilder();
		Formatter formatter = new Formatter(sb, Locale.US);
		double ms = (double) consume / 1000;
		formatter.format("%5.2f %s", ms, sql);
		return formatter.toString();
	}
}
